stap=0.01;seq=seq(.005,.995,.01)
D1=dnorm(seq,0.40,0.04);D1=D1/(sum(D1)*stap)
D2=dnorm(seq,0.70,0.10);D2=D2/(sum(D2)*stap)
G1=(D1+D2)/2
G2=dnorm(seq,0.45,0.15);G2=G2/(sum(G2)*stap)
plot(seq,G1,col='blue',type='l',lwd=2,ylim=c(0,8),axes=FALSE,
main=c(paste('Profile Examples with Profile-Based Cliffs Delta = .29'),
paste('Group 1 (mean=.55) and Group 2 (mean=.45)')),
xlab='Probability of Behaviour',ylab='Plausibility')
axis(side=1,at=seq(0,1,0.10));axis(side=2,at=seq(0,8,2),las=1)
lines(seq,G2,col='red',lwd=2)
legend('topleft',bty='n',
c('Profile Group 1','Profile Group 2'),
fill=c('blue','red'))

# READ IN S1 AND S2

N=0
NPBCD1=numeric()
avesamp1=matrix(,100,10000)
avesamp2=matrix(,100,10000)
while(N<10000)
{
items=5
SAMP1=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S1[x],S1[x]))
SAMP1[x,]=s
}

items=5
SAMP2=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S2[x],S2[x]))
SAMP2[x,]=s
}

stap=0.01;ncel=100;uit_samp1=matrix(0,ncel,1);n_samp1=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP1[i,]),sum(table(SAMP1[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp1=uit_samp1+uiti
  n_samp1=n_samp1+1
}
uit_samp1=uit_samp1/n_samp1

stap=0.01;ncel=100;uit_samp2=matrix(0,ncel,1);n_samp2=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP2[i,]),sum(table(SAMP2[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp2=uit_samp2+uiti
  n_samp2=n_samp2+1
}
uit_samp2=uit_samp2/n_samp2

avesamp1[,N+1]=uit_samp1
avesamp2[,N+1]=uit_samp2

y1=uit_samp1;y2=uit_samp2
DIF=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
dif=(x-1)*stap-(y-1)*stap
DIF[x,y]=dif
}}
DIF=sign(DIF)
DEN=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
den=y1[x]*y2[y]*stap^2
DEN[x,y]=den
}}
CD_real=sum(DIF*DEN)/sum(DEN)
NPBCD1=c(NPBCD1,CD_real)
N=N+1
if(N%%1000==0)print(N)
}
N;mean(NPBCD1);c(sort(NPBCD1)[51],sort(NPBCD1)[9950])

seq=seq(0.005,0.995,0.01)

NX1=apply(avesamp1,1,mean)
NY1=apply(avesamp1,1,sd)
lines(seq,NX1,col='magenta',lwd=2,lty=2)
K1=NX1+2.576*NY1;lines(seq,K1,col='magenta',lty=2)
L1=NX1-2.576*NY1;L1[L1<0]=0;lines(seq,L1,col='magenta',lty=2)

NX2=apply(avesamp2,1,mean)
NY2=apply(avesamp2,1,sd)
lines(seq,NX2,col='green3',lwd=2,lty=2)
K2=NX2+2.576*NY2;lines(seq,K2,col='green3',lty=2)
L2=NX2-2.576*NY2;L2[L2<0]=0;lines(seq,L2,col='green3',lty=2)


############################################################


stap=0.01;seq=seq(.005,.995,.01)
D1=dnorm(seq,0.40,0.04);D1=D1/(sum(D1)*stap)
D2=dnorm(seq,0.70,0.10);D2=D2/(sum(D2)*stap)
G1=(D1+D2)/2
G2=dnorm(seq,0.45,0.15);G2=G2/(sum(G2)*stap)
plot(seq,G1,col='blue',type='l',lwd=2,ylim=c(0,8),axes=FALSE,
main=c(paste('Profile Examples with Profile-Based Cliffs Delta = .29'),
paste('Group 1 (mean=.55) and Group 2 (mean=.45)')),
xlab='Probability of Behaviour',ylab='Plausibility')
axis(side=1,at=seq(0,1,0.10));axis(side=2,at=seq(0,8,2),las=1)
lines(seq,G2,col='red',lwd=2)
legend('topleft',bty='n',
c('Profile Group 1','Profile Group 2'),
fill=c('blue','red'))

N=0
NPBCD2=numeric()
avesamp3=matrix(,100,10000)
avesamp4=matrix(,100,10000)
while(N<10000)
{
items=20
SAMP1=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S1[x],S1[x]))
SAMP1[x,]=s
}

items=20
SAMP2=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S2[x],S2[x]))
SAMP2[x,]=s
}

stap=0.01;ncel=100;uit_samp1=matrix(0,ncel,1);n_samp1=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP1[i,]),sum(table(SAMP1[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp1=uit_samp1+uiti
  n_samp1=n_samp1+1
}
uit_samp1=uit_samp1/n_samp1

stap=0.01;ncel=100;uit_samp2=matrix(0,ncel,1);n_samp2=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP2[i,]),sum(table(SAMP2[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp2=uit_samp2+uiti
  n_samp2=n_samp2+1
}
uit_samp2=uit_samp2/n_samp2

avesamp3[,N+1]=uit_samp1
avesamp4[,N+1]=uit_samp2

y1=uit_samp1;y2=uit_samp2
DIF=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
dif=(x-1)*stap-(y-1)*stap
DIF[x,y]=dif
}}
DIF=sign(DIF)
DEN=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
den=y1[x]*y2[y]*stap^2
DEN[x,y]=den
}}
CD_real=sum(DIF*DEN)/sum(DEN)
NPBCD2=c(NPBCD2,CD_real)
N=N+1
if(N%%1000==0)print(N)
}
N;mean(NPBCD2);c(sort(NPBCD2)[51],sort(NPBCD2)[9950])

seq=seq(0.005,0.995,0.01)

NX3=apply(avesamp3,1,mean)
NY3=apply(avesamp3,1,sd)
lines(seq,NX3,col='magenta',lwd=2,lty=2)
K1=NX3+2.576*NY3;lines(seq,K1,col='magenta',lty=2)
L1=NX3-2.576*NY3;L1[L1<0]=0;lines(seq,L1,col='magenta',lty=2)

NX4=apply(avesamp4,1,mean)
NY4=apply(avesamp4,1,sd)
lines(seq,NX4,col='green3',lwd=2,lty=2)
K2=NX4+2.576*NY4;lines(seq,K2,col='green3',lty=2)
L2=NX4-2.576*NY4;L2[L2<0]=0;lines(seq,L2,col='green3',lty=2)


############################################################


stap=0.01;seq=seq(.005,.995,.01)
D1=dnorm(seq,0.40,0.04);D1=D1/(sum(D1)*stap)
D2=dnorm(seq,0.70,0.10);D2=D2/(sum(D2)*stap)
G1=(D1+D2)/2
G2=dnorm(seq,0.45,0.15);G2=G2/(sum(G2)*stap)
plot(seq,G1,col='blue',type='l',lwd=2,ylim=c(0,8),axes=FALSE,
main=c(paste('Profile Examples with Profile-Based Cliffs Delta = .29'),
paste('Group 1 (mean=.55) and Group 2 (mean=.45)')),
xlab='Probability of Behaviour',ylab='Plausibility')
axis(side=1,at=seq(0,1,0.10));axis(side=2,at=seq(0,8,2),las=1)
lines(seq,G2,col='red',lwd=2)
legend('topleft',bty='n',
c('Profile Group 1','Profile Group 2'),
fill=c('blue','red'))

N=0
NPBCD3=numeric()
avesamp5=matrix(,100,10000)
avesamp6=matrix(,100,10000)
while(N<10000)
{
items=50
SAMP1=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S1[x],S1[x]))
SAMP1[x,]=s
}

items=50
SAMP2=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S2[x],S2[x]))
SAMP2[x,]=s
}

stap=0.01;ncel=100;uit_samp1=matrix(0,ncel,1);n_samp1=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP1[i,]),sum(table(SAMP1[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp1=uit_samp1+uiti
  n_samp1=n_samp1+1
}
uit_samp1=uit_samp1/n_samp1

stap=0.01;ncel=100;uit_samp2=matrix(0,ncel,1);n_samp2=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP2[i,]),sum(table(SAMP2[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp2=uit_samp2+uiti
  n_samp2=n_samp2+1
}
uit_samp2=uit_samp2/n_samp2

avesamp5[,N+1]=uit_samp1
avesamp6[,N+1]=uit_samp2

y1=uit_samp1;y2=uit_samp2
DIF=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
dif=(x-1)*stap-(y-1)*stap
DIF[x,y]=dif
}}
DIF=sign(DIF)
DEN=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
den=y1[x]*y2[y]*stap^2
DEN[x,y]=den
}}
CD_real=sum(DIF*DEN)/sum(DEN)
NPBCD3=c(NPBCD3,CD_real)
N=N+1
if(N%%1000==0)print(N)
}
N;mean(NPBCD3);c(sort(NPBCD3)[51],sort(NPBCD3)[9950])

seq=seq(0.005,0.995,0.01)

NX5=apply(avesamp5,1,mean)
NY5=apply(avesamp5,1,sd)
lines(seq,NX5,col='magenta',lwd=2,lty=2)
K1=NX5+2.576*NY5;lines(seq,K1,col='magenta',lty=2)
L1=NX5-2.576*NY5;L1[L1<0]=0;lines(seq,L1,col='magenta',lty=2)

NX6=apply(avesamp6,1,mean)
NY6=apply(avesamp6,1,sd)
lines(seq,NX6,col='green3',lwd=2,lty=2)
K2=NX6+2.576*NY6;lines(seq,K2,col='green3',lty=2)
L2=NX6-2.576*NY6;L2[L2<0]=0;lines(seq,L2,col='green3',lty=2)


############################################################


stap=0.01;seq=seq(.005,.995,.01)
D1=dnorm(seq,0.40,0.04);D1=D1/(sum(D1)*stap)
D2=dnorm(seq,0.70,0.10);D2=D2/(sum(D2)*stap)
G1=(D1+D2)/2
G2=dnorm(seq,0.45,0.15);G2=G2/(sum(G2)*stap)
plot(seq,G1,col='blue',type='l',lwd=2,ylim=c(0,8),axes=FALSE,
main=c(paste('Profile Examples with Profile-Based Cliffs Delta = .29'),
paste('Group 1 (mean=.55) and Group 2 (mean=.45)')),
xlab='Probability of Behaviour',ylab='Plausibility')
axis(side=1,at=seq(0,1,0.10));axis(side=2,at=seq(0,8,2),las=1)
lines(seq,G2,col='red',lwd=2)
legend('topleft',bty='n',
c('Profile Group 1','Profile Group 2'),
fill=c('blue','red'))

N=0
NPBCD4=numeric()
avesamp7=matrix(,100,10000)
avesamp8=matrix(,100,10000)
while(N<10000)
{
items=200
SAMP1=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S1[x],S1[x]))
SAMP1[x,]=s
}

items=200
SAMP2=matrix(0,500,items)
for(x in 1:500)
{
s=sample(c(0,1),items,replace=TRUE,prob=c(1-S2[x],S2[x]))
SAMP2[x,]=s
}

stap=0.01;ncel=100;uit_samp1=matrix(0,ncel,1);n_samp1=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP1[i,]),sum(table(SAMP1[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp1=uit_samp1+uiti
  n_samp1=n_samp1+1
}
uit_samp1=uit_samp1/n_samp1

stap=0.01;ncel=100;uit_samp2=matrix(0,ncel,1);n_samp2=0
for (i in 1:500)
{
  db=dbinom(sum(SAMP2[i,]),sum(table(SAMP2[i,])),seq)
  uiti=matrix(db,ncel,1)/(sum(db)*stap)
  uit_samp2=uit_samp2+uiti
  n_samp2=n_samp2+1
}
uit_samp2=uit_samp2/n_samp2

avesamp7[,N+1]=uit_samp1
avesamp8[,N+1]=uit_samp2

y1=uit_samp1;y2=uit_samp2
DIF=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
dif=(x-1)*stap-(y-1)*stap
DIF[x,y]=dif
}}
DIF=sign(DIF)
DEN=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
den=y1[x]*y2[y]*stap^2
DEN[x,y]=den
}}
CD_real=sum(DIF*DEN)/sum(DEN)
NPBCD4=c(NPBCD4,CD_real)
N=N+1
if(N%%1000==0)print(N)
}
N;mean(NPBCD4);c(sort(NPBCD4)[51],sort(NPBCD4)[9950])

seq=seq(0.005,0.995,0.01)

NX7=apply(avesamp7,1,mean)
NY7=apply(avesamp7,1,sd)
lines(seq,NX7,col='magenta',lwd=2,lty=2)
K1=NX7+2.576*NY7;lines(seq,K1,col='magenta',lty=2)
L1=NX7-2.576*NY7;L1[L1<0]=0;lines(seq,L1,col='magenta',lty=2)

NX8=apply(avesamp8,1,mean)
NY8=apply(avesamp8,1,sd)
lines(seq,NX8,col='green3',lwd=2,lty=2)
K2=NX8+2.576*NY8;lines(seq,K2,col='green3',lty=2)
L2=NX8-2.576*NY8;L2[L2<0]=0;lines(seq,L2,col='green3',lty=2)